

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>

#include "common/utils.hpp"

TreeNode* invertTree(TreeNode* root) {
    std::stack<TreeNode*> stack;

    if (root != nullptr) stack.push(root);

    while(!stack.empty()) {
        TreeNode* node = stack.top();
        stack.pop();

        std::swap(node->left, node->right);
        if (node->right) stack.push(node->right);
        if (node->left) stack.push(node->left);
    }

    return root;
}

extern TreeNode* commonRoot;

int main() {
    printTreeNode(commonRoot);
    invertTree(commonRoot);
    printTreeNode(commonRoot);
}